package com.adms.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.adms.domain.Patrol;
import com.adms.service.PatrolService;

@RequestMapping("patrol")
@RestController
public class PatrolController {
	@Autowired
	private PatrolService patrolService;
	
	@GetMapping
	public Object list(Patrol patrol,String timeField,Date start,Date end,String orderByClause,String key,Boolean isSelf,
			@RequestParam(defaultValue = "1") Integer pageNum,
			@RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return patrolService.list(patrol,timeField,start,end,orderByClause,key,isSelf,pageNum,pageSize,navigatePages);
	}
	
	@GetMapping("{patrolId}")
	public Object getBypatrolId(@PathVariable("patrolId") Integer patrolId) {
		return patrolService.getByPatrolId(patrolId);
	}
	
	@PostMapping("create")
	public Object create(Patrol patrol) {
		return patrolService.creat(patrol);
	}
	
	@PostMapping("delete")
	public Object delete(@RequestParam("patrolIds") int[] patrolIds) {
		return patrolService.delete(patrolIds);
	}
	
	@PostMapping("update")
	public Object update(Patrol patrol) {
		return patrolService.update(patrol);
	}
}
